package com.eastfair.datasync.listener;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.eastfair.datasync.entity.CanalData;
import com.eastfair.datasync.enumeration.MysqlBusinessEnum;
import com.eastfair.datasync.util.CanalUtil;

import java.util.ArrayList;
import java.util.List;

public abstract class SyncAbstract<T> implements SyncInterface<T> {

    @Override
    public void executeAll(String message, T t) {
        CanalData<T> canalData = CanalUtil.parseData(message, (Class) t);
        if(canalData==null){
            return;
        }
        if(MysqlBusinessEnum.INSERT.eq(canalData.getMysqlBusinessEnum())){
            executeInsert(canalData);
        }else if(MysqlBusinessEnum.UPDATE.eq(canalData.getMysqlBusinessEnum())){
            executeUpdate(canalData);
        }else if(MysqlBusinessEnum.ALTER.eq(canalData.getMysqlBusinessEnum())){
            executeAlter(canalData);
        }else if(MysqlBusinessEnum.DELETE.eq(canalData.getMysqlBusinessEnum())){
            executeAlter(canalData);
        }
    }


}
